<h2>Why is this an issue?</h2>
<p>The use of a <code>StringBuilder</code> or <code>StringBuffer</code> makes <code>String</code> assembly more efficient than plain concatenation
when you perform a large number of appends. Using <code>String</code> concatenation within <code>StringBuilder.append</code> defeats the purpose of
the <code>StringBuilder</code>. If you concatenate only a few strings, use direct <code>String</code> concatenation. Otherwise, replace
<code>String</code> concatenation with calls to <code>append</code>.</p>
<p>This rule applies to String concatenations performed repeatedly, inside loops. In such scenarios, the performance penalty associated with
inefficient StringBuilder.append usage can multiply significantly.</p>
<h3>Noncompliant code example</h3>
<pre data-diff-id="1" data-diff-type="noncompliant">
StringBuilder sb = new StringBuilder();
for (String name : names) {
  sb.append("Hello : " + name); // Noncompliant
}
</pre>
<h3>Compliant solution</h3>
<pre data-diff-id="1" data-diff-type="compliant">
StringBuilder sb = new StringBuilder();
for (String name : names) {
  sb.append("Hello : ").append(name);
}
</pre>
<h2>Resources</h2>
<h3>Benchmarks</h3>
<table>
  <colgroup>
    <col style="width: 25%;">
    <col style="width: 25%;">
    <col style="width: 25%;">
    <col style="width: 25%;">
  </colgroup>
  <thead>
    <tr>
      <th>Method</th>
      <th>Runtime</th>
      <th>Average time</th>
      <th>Error margin</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><p>append</p></td>
      <td><p>Temurin 21</p></td>
      <td><p>14.26 ns/op</p></td>
      <td><p>±0.50 ns/op</p></td>
    </tr>
    <tr>
      <td><p>concat</p></td>
      <td><p>Temurin 21</p></td>
      <td><p>17.77 ns/op</p></td>
      <td><p>±0.66 ns/op</p></td>
    </tr>
    <tr>
      <td><p>concatWithinBuilder</p></td>
      <td><p>Temurin 21</p></td>
      <td><p>31.42 ns/op</p></td>
      <td><p>±1.80 ns/op</p></td>
    </tr>
  </tbody>
</table>
<p>The results were generated by running the following snippet with <a href="https://github.com/openjdk/jmh">jmh</a>:</p>
<pre>
private String name1 = "John";
private String name2 = "Jane";

@Benchmark
public String concat() {
  return name1 + ", " + name2;
}

@Benchmark
public String concatWithinBuilder() {
  return new StringBuilder()
    .append(name1 + ", " + name2)
    .toString();
}

@Benchmark
public String append() {
  return new StringBuilder()
    .append(name1)
    .append(", ")
    .append(name2)
    .toString();
}
</pre>

